package com.admin.business.venusSysRoleMenu;

import com.tiangong.framework.annotation.OpenApi;
import com.tiangong.framework.bo.CDO;
import com.tiangong.framework.bo.Return;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @description: 角色菜单关联表
 * @create: 2022-03-22 18:46:06
 **/
@Service("venusSysRoleMenu")
@Slf4j
public class VenusSysRoleMenuService{

    @Resource
    VenusSysRoleMenuDao venusSysRoleMenuDao;

    /**
     * 添加角色菜单关联表,获取id数据
     *
     * @param cdoRequest - role_id:
     *                   - menu_id:
     *                   - id:
     * @return
     * @author ht
     * @create: 2022-03-22 18:46:06
     */
    @OpenApi
    public Return addVenusSysRoleMenu(CDO cdoRequest) {
        venusSysRoleMenuDao.addVenusSysRoleMenu(cdoRequest);
        CDO cdoResult = new CDO();
        if (cdoRequest.containsKey("id")) {
            cdoResult.set("id", cdoRequest.get("id"));
        }
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据id，更新角色菜单关联表数据
     *
     * @param cdoRequest - role_id:
     *                   - menu_id:
     *                   - id:
     * @return
     * @author ht
     * @create: 2022-03-22 18:46:06
     */
    @OpenApi
    public Return updateVenusSysRoleMenuById(CDO cdoRequest) {
        int affectedRows = venusSysRoleMenuDao.updateVenusSysRoleMenuById(cdoRequest);
        CDO cdoResult = new CDO();
        cdoResult.set("affectedRows", affectedRows);
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据id，删除角色菜单关联表数据
     *
     * @param cdoRequest - id:
     * @return
     * @author ht
     * @create: 2022-03-22 18:46:06
     */
    @OpenApi
    public Return deleteVenusSysRoleMenuById(CDO cdoRequest){
        int affectedRows = venusSysRoleMenuDao.deleteVenusSysRoleMenuById(cdoRequest.getInteger("id"));
        CDO cdoResult = new CDO();
        cdoResult.set("affectedRows", affectedRows);
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据条件，删除角色菜单关联表数据
     *
     * @param cdoRequest - role_id:
     *                   - menu_id:
     * @return
     * @author ht
     * @create: 2022-03-22 18:46:06
     */
    @OpenApi
    public Return deleteVenusSysRoleMenu(CDO cdoRequest) {
        int affectedRows = venusSysRoleMenuDao.deleteVenusSysRoleMenu(cdoRequest);
        CDO cdoResult = new CDO();
        cdoResult.set("affectedRows", affectedRows);
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据ID，获取角色菜单关联表数据
     *
     * @param cdoRequest - id:
     * @return
     * @author ht
     * @create: 2022-03-22 18:46:06
     */
    @OpenApi
    public Return getVenusSysRoleMenuById(CDO cdoRequest) {
        CDO cdoMapperResult = venusSysRoleMenuDao.getVenusSysRoleMenuById(cdoRequest.getInteger("id"));
        return Return.valueOf(cdoMapperResult);
    }

    /**
     * 根据混合条件，获取角色菜单关联表数据
     *
     * @param cdoRequest - role_id:
     *                   - menu_id:
     *                   - id:
     * @return
     * @author ht
     * @create: 2022-03-22 18:46:06
     */
    @OpenApi
    public Return getVenusSysRoleMenu(CDO cdoRequest) {
        CDO cdoMapperResult = venusSysRoleMenuDao.getVenusSysRoleMenu(cdoRequest);
        return Return.valueOf(cdoMapperResult);
    }

    /**
     * 根据非空条件，获取角色菜单关联表数据列表
     *
     * @param cdoRequest - role_id:
     *                   - menu_id:
     * @return
     * @author ht
     * @create: 2022-03-22 18:46:06
     */
    @OpenApi
    public Return getVenusSysRoleMenuList(CDO cdoRequest) {
        Integer pageIndex = cdoRequest.containsKey("pageIndex") ? cdoRequest.getInteger("pageIndex") : 0;
        int recordSize = cdoRequest.containsKey("recordSize") ? cdoRequest.getInteger("recordSize") : 10;
        cdoRequest.set("recordFrom", pageIndex * recordSize);
        cdoRequest.set("recordSize", recordSize);
        List<CDO> cdoMapperResultList = venusSysRoleMenuDao.getVenusSysRoleMenuList(cdoRequest);
        boolean isEndPage = false;
        if (cdoMapperResultList.size() < recordSize) {
            isEndPage = true;
        }
        CDO cdoResult = new CDO();
        cdoResult.set("isEndPage", isEndPage);
        cdoResult.set("datalist", cdoMapperResultList);
//        int total = venusSysRoleMenuDao.getVenusSysRoleMenuListCount(cdoRequest);
//        cdoResult.set("total", total);
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据混合条件，获取角色菜单关联表数据列表
     *
     * @param cdoRequest - role_id:
     *                   - menu_id:
     *                   - id:
     * @return
     * @author ht
     * @create: 2022-03-22 18:46:06
     */
    @OpenApi
    public Return getVenusSysRoleMenuListByCondition(CDO cdoRequest) {
        Integer pageIndex = cdoRequest.containsKey("pageIndex") ? cdoRequest.getInteger("pageIndex") : 0;
        int recordSize = cdoRequest.containsKey("recordSize") ? cdoRequest.getInteger("recordSize") : 10;
        cdoRequest.set("recordFrom", pageIndex * recordSize);
        cdoRequest.set("recordSize", recordSize);
        List<CDO> cdoMapperResultList = venusSysRoleMenuDao.getVenusSysRoleMenuListByCondition(cdoRequest);
        boolean isEndPage = false;
        if (cdoMapperResultList.size() < recordSize) {
            isEndPage = true;
        }
        CDO cdoResult = new CDO();
        cdoResult.set("isEndPage", isEndPage);
        cdoResult.set("datalist", cdoMapperResultList);
//        int total = venusSysRoleMenuDao.getVenusSysRoleMenuListByConditionCount(cdoRequest);
//        cdoResult.set("total", total);
        return Return.valueOf(cdoResult);
    }
}
